var app = angular.module('ma-forcebuilder.services', []);

app.factory('Faction', function($http){
    var URI = '/api/faction';

    var Faction = function(data) {
        angular.extend(this, data);
    }

    Faction.list = function() {
        return $http.post(URI + '.list', {}).then(function(result){
            return result.data.factions;
        });
    }

    return Faction;
});

app.factory('Unit', function($http){
    var URI = '/api/unit';

    var Unit = function(data) {
        angular.extend(this, data);
    }

    Unit.allByFaction = function(factionId) {
        return $http.post(URI + '.list_by_faction', { 'faction' : factionId })
            .then(function(result){
                return result.data.units;
            });
    }

    return Unit;
});